home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
qbfe10.arc
/
EDITTEST.BAS
< prev
next >
Wrap
BASIC Source File
|
1987-11-27
|
16KB
|
378 lines
'
' EditField
'
' Version 1.0
'
' (For Use With Microsoft's QuickBASIC Compiler V4.0)
'
' (C) 1987 By Tony Elliott
'
'
' Please refer any comments, bugs or suggestions to
'
' Tony Elliott c/o
' Programmer's Information Exchange
' (404) 928-0033
'
' Support for this routine as well as help, comments, suggestions..etc for
'any of your QuickBASIC projects can be found on Programmer's Information
'Exchange. Financial support for this routine is not required. As an
'alternative, I suggest becoming a supporting user of P.I.E. ($10 per year
'until Dec. 31).
'
'
' This routine is released into the Public Domain under the following
'conditions:
'
' 1) All files in this ARChive must be distributed in their
' ORIGINAL, UNMODIFIED form. If you correct a bug, make an
' enhancement, please upload it to Programmer's Information
' Exchange BBS as a PRIVATE file for the Sysop. After reviewing
' any changes, appropriate credit will be given in the documentation
' and a new release will be made through P.I.E.
'
' 2) The following files must be included in the distribution
' archive:
' EDITFLD.BAS - Source Code for EditField
' STATLINE.BAS - Source Code for Statline
' EDITTEST.BAS - Test-bed Program & Documentation
' HISTORY.DOC - Revision history
' README.1ST - Special Instructions
'
'
' Brief Description
'
'
' After trying many field editing routines available in the BBS circuit,
'shareware and public domain, I never found one that was a 'editor for all
'occassions.' So, I decided to write EditField.
'
'In designing the routine, I tried to keep two primary objectives in mind:
'
' 1) It had to suit almost all needs as a numeric field editor AND a
' text field editor, but had to be easily interchangable.
'
' 2) I wanted the programmer to be able to specify EXACTLY what type of
' data was to be returned by the routine (minimum/maximum values for
' numeric fields and if a nul/zero-value string was allowed) so a
' minimum of additional code would be required to check the validity of
' the data returned.
'
'
' The call to the EditField subprogram has only four arguments. The rest of
'the required variables are defined in a "common block" statment. More on
'that later.
'
' EditField also calls a routine called "Statline" (included) to display
'error/status information of line 25. If you do not like the way that
'EditField handles this, you may write your own StatLine subprogram for
'EditField to call. Please look at the StatLine source code for more info on
'how this is currently being handled.
'
' EditField is set apart from other field editors in several ways. Most
'importantly (in my opinion), is the FORMAT$ argument. FORMAT$ uses a
'sub-set of the BASIC's PRINT USING syntax so that the length of the field
'AND the exact display format is easily defined.
'
' EditField funtions in either a text entry mode or numeric entry mode.
'This mode is determined by the FORMAT$ arguments. This is described in more
'detail later. First I am going to cover the arguments that are common to
'both modes and then I will describe the mode specific arguments and
'functions. Please keep in mind that a few of the arguments have different
'functions and different valid values in each mode.
'
'
' Syntax:
'
' CALL EditField(old$, ed$, format$, retflag%)
'
'
'The routine also requires the presence of a "common block" defining the
'other required variables. Once defined, these variables are shared by the
'EditField routine so you do not have to specify them in a CALL statement
'with a seemingly endlist list of arguments. The values of these common
'block variables can be changed anywhere in your main program module.
'
' You do not necessarly need to know how the common block functions to use
'it. Just copy the example below into your program. It must be placed before
'any execuatable statements. A "DEFINT A-Z" must precede the common block
'statement. All statements in QB4 are executable except for COMMON, CONST,
'DATA, DEFtype, DIM (for static arrays), OPTION BASE, REM, SHARED, STATIC,
'TYPE...END TYPE, and all Metacommands.
'
'Common block syntax: (All variables are integers unless otherwise defined)
'
' COMMON /editfld/ row, col, ucase, minval!, maxval!, justify,_
' padchar, keystat, kfg, kbg, krow, kcol, sfg, sbg, sfg, dbg, insmode,_
' nul, alarm
'
' Please note that QuickBASIC v4.0 does not allow you to join multiple
'physical lines into one logical line using the underscore "_" character.
'It was done here for display purposes only.
'
'
' As you can see, there are many parameters assoicatied with this routine.
'There are also allot of features packed in here, so read on a bit before
'you get discouraged!
'
'
' Variables Common to Both Modes
'
' old$ - Any text to be edited. If you are going to edit a numeric field
' and wish to pass a numeric argument to the routine, it must first
' be converted to a string. (Example: old$=STR$(number))
'
' ed$ - The edited data returned from the routine. If you were editing a
' numeric field, you may convert the contents of ed$ back into a
' numeric variable. (Example: number=val(ed$))
'
' row \ The row and column of screen location where editing is to take
' col / place. (Default is current cursor position).
'
' sfg \ The foreground (sfg) and the background (sbg) colors of the field
' sbg / during editing. (Default: sfg=0 sbg=7)
'
' dfg \ The foreground and background colors that the field will be displayed
' dbg / in when the routine is exited. (Default: dfg=7 dbg=0)
'
'keystat - If set to a non-zero value, a status display will be available for
' the INSert key, CAPS lock, and NUMber lock keys. If active, the
' following arguments must also be defined:
'
' krow \ Row and column screen positon where the 9 character status
' kcol / display will be placed.
' kfg \ Foreground and background colors of the status display. If
' kbg / krow, kcol, kfg or kbg are not defined, keystat will be
' disabled.
'
'
'retflag - The routine exit condition flag. If the user exited normally
' (by pressing enter at the end of a valid field), it will be set
' to 0. If the user aborted (pressed ESC), it will be set to 1.
' If an invalid format$ argument was used, 99 will be returned.
' If a value is returned other than those specified above, an
' "extended key" was pressed (one not used by the routine) and the
' code of that key is in retflag.
'
' nul - If set to a non-zero value, the routine will not allow a nul (empty)
' string to be returned. Or, if in the numeric mode, it will not
' allow a zero value to be returned (obeying minval!/maxval!). This
' is useful where input would be REQUIRED (name or age). Default=0.
'
'alarm - Set to a non-zero value to DISABLE the BEEP on errors. You can
' define your own alarm sound by changing the "Alarm" subroutine in
' EDITFLD module.
'
'
' Variables Specific to the Text Entry Mode
'
'
'format$ - To initiate the text entry mode, the first and last character of
' format$ must be the "\" (as in the PRINT USING syntax) with spaces
' in between. The total length of format$ will be the maximim
' length of the field. For example:
'
' format$="\ \" A 15 character text field
' format$="\\" A 2 character text field
'
' ucase = 0 No case conversion is performed.
' = 1 FORCES ALL UPPER CASE
' = 2 forces all lower case
'
'justify= 0 No justification is performed. The string is returned without
' any "padding" spaces on either side. The returned string and
' the displayed field are both affected by 1,2 and 3 below.
' = 1 String is returned "Left Justified" (spaces fill the remaining
' length of the field - the text entered is on the LEFT side).
' = 2 String is returned "Right Justified." Justification will not
' occur until the routine is exited.
' = 3 String is returned centered (and displayed centered). Again,
' centering will not occur until the routine is exited.
'
'insmode - If set to a non-zero, the insert mode will be toggled ON upon
' entering the routine. While ON, the cursor in the form of a solid
' block, and when OFF in the form of a flat line.
' Editing will begin from the left side of an existing field upon
' entering the routine with this toggled ON, and from the right side
' if OFF (personal preference).
'
'padchar - Set this to the ascii value of the character to be used to fill in
' "empty" spaces in the field. Default=32 (space)
'
' (minval! / maxval! are ignored while in the text mode)
'
'
'
' Variables Specific to the Numeric Mode
'
'format$ - In order to invoke the numeric mode, the first character of format$
' must be "#". The only valid characters allowed in format$ when
' defining a numeric field is "#" and "." When exiting the routine,
' any values entered will be displayed using format$ just as if the
' value have been displayed via PRINT USING.
' Valid example are:
'
' format$="###.##" - Will allow entry of values from 0 to 999
' obeying minval!/maxval! and nul. Upon
' exiting the routine, the value entered
' will be displayed using this format.
'
' format$="#####" - Allow values from 0 to 99,999. If a
' decimal is entered, the routine will accept
' it, but will round the value off to an
' integer.
'
' A couple of things to keep in mind .. minval!/maxval! have priority
' over the routine's built-in min/max value calculation. Be sure
' you do not define a maxval! greater that the format$'s ability to
' display. Also, the range of allowable numeric entry is confined to
' BASIC's limitations on single percision variables.
'
' minval! \ Defines the minimum and maximum allowable values for entry. The
' maxval! / use must enter a value with this range or abort (ESC).
'
' nul - If set to a non-zero, the routine will only accept a non-zero value
' obeying minval!/maxval!. Default=0
'
'
'********* Please Note: The functions of the following two arguments
' differ from the text mode!
'
'justify - If set to a non-zero, the special numeric formatting will be
' removed from ed$. The field will still display the value according
' to format$. Default=0
'
' ucase - If set to a non-zero and a value was assigned to old$ to be edited,
' the "old" value will be erased at the first valid keystroke.
' The user would have to enter the new value from scratch. If set to
' 0, text mode type editing is available.
'
' (padchar is ignored in the numeric mode)
'
'
'
' Valid Editing Keys
'
' Left Arrow - Move cursor to left one character
'
' Right Arrow - Move cursor to right one character
'
' Home - Move cursor to left side of field
'
' End - Move cursor to right side of field
'
' Ins - Toggles the insert mode ON/OFF. Cursor is a block shape when ON.
'
' Del - Deletes character at cursor position. All characters to the right of
' the cursor are moved to the left one space.
'
'(Backspace) - Deletes the character to the left of the cursor. All char-
' acters at, and to the right of the cursor will be moved to the
' left one space.
'
' Cntrl-Right Arrow - Move to the right one word.
'
' Cntrl-Left Arrow - Move to the left one word.
'
' Cntrl-Home - Deletes the contents of the field.
'
' (Enter) - Exits the routine if the contents of field are within the
' parameters defined in the arguments. Sets retflag to 0
'
' (Esc) - If the current contents of the field differs from old$, the
' original field contents are restored (acts as an UNDO key).
' If pressed a second consecutive time (or if the current contents
' of the field matchs old$) the routine will abort, setting
' retflag to 1
'
'
'****************************************************************************
' W A R N I N G ! !
'
' EditField uses three routines from the ADVBAS 3.42 library (not included).
'
'XQPRINT - Routine for direct screen writes > In XQPRINT.OBJ
'SETKBD - Set the CAPS, INS, NUM lock key mode \ Both of these routines
'GETKBD - Get the CAPS, INS, NUM lock key status / are in KBD.OBJ
'CALCATTR- Calculates screen color attributes > In CALCATTR.OBJ
'
' Be sure to include these in your .LIB & .QLB libraries before attempting to
'run these routines.
'
' There have been reports that some of the ADVBAS routines written for
'QB2 & QB3 are not compatible with QB4. Although I have tested these routines
'(specifically XQPRINT, SETKBD, GETKBD) in programs of various sizes without
'problem, I strongly suggest you replace these routines with ones written for
'QB4 (ProBAS by Hammerly Computer Services, Inc, HIGHLY recommended).
'
'*****************************************************************************
' Please keep in mind.. this is just a "shell" to get you started. It is not
'intended to be an elaborate demo of EditField.
DEFINT A-Z
COMMON /editfld/ row, col, ucase, minval!, maxval!, justify, padchar, keystat, kfg, kbg, krow, kcol, sfg, sbg, dfg, dbg, insmode, nul, alarm
DECLARE SUB EditField (old$, ed$, format$, retflag)
'Just a basic set-up to get things rolling...
'row=10 : col=20 'Field position (Disabled. Uses current cursor pos)
sfg = 4: sbg = 7 'Editing colors
dfg = 14: dbg = 0 'Display colors (used when exiting routine)
keystat = 1 'Turn on key status display
kfg = 9: kbg = 0 'Colors of the key status display
krow = 1: kcol = 70 'Position of the key status display
insmode = 0 'Insert OFF
alarm = 0 'Error alarm ON
' Main Program
CLS
LOCATE 3, 15: PRINT "You may now edit this field. Please refer to the"
LOCATE 4, 15: PRINT "EDITTEST.BAS file for editing instructions"
'Edit a text field
COLOR 6, 0
LOCATE 10, 1
PRINT "Your Favorite BBS: ";
old$ = "Programmer's Information Exchange"
format$ = "\ \"
padchar = 254
justify = 0
CALL EditField(old$, ed$, format$, retflag)
GOSUB ShowResults
'Edit a numeric field
LOCATE 12, 1
PRINT "Approximate Cost of Your Computer: $";
old$ = "1295.50"
ucase = 1
format$ = "####.##"
minval! = 100
maxval! = 9999.99
CALL EditField(old$, ed$, format$, retflag)
GOSUB ShowResults
END
'
'****************************************************************************
' PROGRAM SUBROUTINES
'****************************************************************************
'
'Prints results
ShowResults:
COLOR 7, 0
LOCATE 18, 1
PRINT SPC(79);
LOCATE 18, 1
PRINT "String Returned: "; : COLOR 6: PRINT ed$
COLOR 7
PRINT "RETFLAG="; : COLOR 6: PRINT retflag
RETURN